package com.marion.study.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Properties;

@AllArgsConstructor
@Builder
public class User {

    private int id;

    private String name;

    private int age;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public User() {
        this.configFromProperties(System.getProperties());
    }

    public void configFromProperties(Properties properties) {
        String id = properties.getProperty("user.id");
        if (id != null && id.length() > 0) {
            int pid = Integer.parseInt(id);
            this.setId(pid);
        }

        String name = properties.getProperty("user.name");
        if (name != null && name.length() > 0) {
            this.setName(name);
        }

        String age = properties.getProperty("user.age");
        if (age != null && age.length() > 0) {
            int page = Integer.parseInt(age);
            this.setAge(page);
        }
    }

}
